package customerEnter.Frame.Login;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class LoginXML {

	@SuppressWarnings({ "rawtypes" })
	public static List<Map<String, String>> getLogXMl(String URl) {
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		File f = new File(URl);
		SAXReader reader = new SAXReader();
		Document document = null;
		Element root = null;
		Iterator it = null;
		try {
			document = reader.read(f);
			root = document.getRootElement();
			it = root.elementIterator();
		} catch (DocumentException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Map<String, String> map1 = new HashMap<String, String>();
		Map<String, String> map2 = new HashMap<String, String>();
		while (it.hasNext()) {
			Element element = (Element) it.next();
			Iterator eleIt = element.elementIterator();
			while (eleIt.hasNext()) {
				Element e = (Element) eleIt.next();

				if ("request".equals(e.getName())) {
					map1.put(e.getTextTrim(), e.getTextTrim());
				}
				if ("name".equals(e.getName())) {
					map2.put(e.getTextTrim(), e.getTextTrim());
				}

			}
		}
		list.add(map1);
		list.add(map2);
		return list;
	}

	public static void main(String[] args) {
		getLogXMl("E:\\java\\apache-tomcat-8.0.33\\webapps\\yez_easyBuyMall\\WEB-INF\\classes\\UserLogin.xml");
	}
}
